﻿using System;

namespace DotNetCommon.Validate.Annotations;

/// <summary>
/// 必须可以转换到类型T(即: object.To&lt;T>() 可以成功), 示例:
/// <code>
/// //必须可以转换成指定枚举
/// [VMustCanConvertTo&lt;EnumStatus?>]
/// public string Status { get; set; }
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public sealed class VMustCanConvertToAttribute<T>(string errorMessage = null) : Attribute, IValidateAction
{
    public string ErrorMessage { get; } = errorMessage;

    public void Action(IValidateContext ctx)
    {
        ValidateExtensions.MustCanConvertToInternal<T>(ctx, ErrorMessage);
    }
}
